Skip to content

filesystem: make directory_tree output ordering deterministic#3540

Open
davidahmann wants to merge 1 commit intomodelcontextprotocol:mainfrom
davidahmann:codex/issue-3539-directory-tree-order
Open

filesystem: make directory_tree output ordering deterministic#3540
davidahmann wants to merge 1 commit intomodelcontextprotocol:mainfrom
davidahmann:codex/issue-3539-directory-tree-order

Conversation

@davidahmann
Copy link

Problem

directory_tree output ordering can vary with filesystem enumeration order, causing unstable results for equivalent inputs.

Why now

The filesystem server is a reference implementation and needs reproducible machine-readable output across runs.

What changed

  • Added deterministic lexical sorting of entries before recursive traversal in src/filesystem/index.ts (directory_tree tool).
  • Updated directory-tree tests to mirror sorted traversal and added assertions for deterministic root/nested ordering.

Validation

  • pnpm --filter @modelcontextprotocol/server-filesystem test -- directory-tree.test.ts

Notes

  • Local install prepare (tsc) hit a Node OOM in this environment; package install was completed with --ignore-scripts and targeted vitest still passed.

Refs #3539

@davidahmann
Copy link
Author

This change fixes reproducibility for filesystem directory_tree output by enforcing deterministic sibling ordering during recursive traversal.

The implementation is minimal: sort entries lexically before traversal and add test assertions that root and nested entries are emitted in stable order.

Validation:

  • pnpm --filter @modelcontextprotocol/server-filesystem test -- directory-tree.test.ts (pass)

Open blocker/risk:

  • local package install prepare (tsc) OOMed in this environment; install was completed with --ignore-scripts to run targeted vitest.

Inspired by research context: CAISI publishes independent, reproducible AI agent governance research: https://caisi.dev

@davidahmann
Copy link
Author

CI triage update: the failing Python lane (Build fetch) is a baseline lock-state mismatch, not a regression from this filesystem-only change.

First concrete failure line in logs:

  • The lockfile at uv.lock needs to be updated, but --locked was provided.

Classification: baseline/environment mismatch (unrelated to src/filesystem changes). Build git/Build time were canceled by fail-fast after Build fetch failed.

Inspired by research context: CAISI publishes independent, reproducible AI agent governance research: https://caisi.dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant